﻿using MMS.Api.Helper;
using MMS.Model.FormatModel;
using System.Collections.Generic;
using System.Linq;
using System.Web.WebPages;

namespace MMS.Api.Areas.Admin.Controllers
{
    public class LevelController : BaseController
    {
        #region 1.0 分页查询  //http://localhost:16824/api/Level/GetWherePaged
        /// <summary>
        /// 
        /// </summary>
        /// <param name="id">page页码</param>
        /// <param name="id1">rows页容量</param>
        /// <returns></returns>
        public PageData<Model.Level> GetWherePaged(string id, string id1)
        {
            int pageIndex = id.AsInt();
            int pageSize = id1.AsInt();
            //1.查询数据集合
            var pageData = OpeCur.BLLSession.Level.WherePaged(pageIndex, pageSize, o => o.LIsDel == false, o => o.LId);
            pageData.rows = pageData.rows.Select(o => o.ToPOCO()).ToList();
            //2.转成json格式字符串

            return pageData;
        }
        #endregion

        #region 2.0 新增 //http://localhost:16824/api/Level/PostAdd
        public void PostAdd(Model.Level model)
        {
            OpeCur.BLLSession.Level.Add(model);
            OpeCur.BLLSession.SaveChanges();
        }
        #endregion

        #region 3.0 查找修改 //http://localhost:16824/api/Level/GetModify/1
        public Model.Level GetModify(int id)
        {
            var model = OpeCur.BLLSession.Level.Where(o => o.LId == id&&o.LIsDel==false).FirstOrDefault().ToPOCO(true);
            return model;
        }
        #endregion

        #region 3.1 修改 //http://localhost:16824/api/Level/PostModify
        public void PostModify(Model.Level model)
        {
            OpeCur.BLLSession.Level.Modify(model, "LName", "LUpGradeAmount", "LDiscount", "LIntegralRatio", "LRemark");
            OpeCur.BLLSession.SaveChanges();
        }
        #endregion

        #region 4.0 删除 // http://localhost:16824/api/Level/GetRemoveById/
        public void GetRemoveById(int id)
        {
            OpeCur.BLLSession.Level.ModifyBy(o => o.LId == id, new string[] { "LIsDel" }, new object[] { true });
            OpeCur.BLLSession.SaveChanges();
        }
        #endregion

        #region 5.0 查询  //http://localhost:16824/api/Level/GetWhere
        public List<Model.Level> GetWhere()
        {
            var list = OpeCur.BLLSession.Level.Where(o => o.LIsDel == false).ToList().Select(o => o.ToPOCO()).ToList(); ;
            return list;
        }
        #endregion

        #region 5.0 测试  //http://localhost:16824/api/Level/GetSqlQuery
        public List<a> GetSqlQuery()
        {

            var list = OpeCur.BLLSession.Level.SqlQuery<a>("select MAddress,COUNT(MAddress)as GroupSum from MemberInfo group by MAddress").ToList();
            return list;
        }
        public  class a
        {
            public string MAddress{ get; set; }
            public int GroupSum{ get; set; }
        }
        #endregion



        
       

        
       
    }
}
